package com.mall.ware.controller;

import com.mall.common.utils.BaseResult;
import com.mall.common.utils.PageUtils;
import com.mall.ware.entity.PurchaseEntity;
import com.mall.ware.service.PurchaseService;
import com.mall.ware.vo.MergeVo;
import com.mall.ware.vo.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 采购信息
 *
 * @author rose
 * @email zichuanhaoyue@mail.com
 * @date 2021-05-16 20:46:32
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {


    @Autowired
    private PurchaseService purchaseService;


    @PostMapping("/done")
    public BaseResult finish(@RequestBody PurchaseDoneVo purchaseDoneVo){

        purchaseService.finish(purchaseDoneVo);

        return BaseResult.ok();
    }

    /**
     *  领取采购单
     *
     * @param ids
     * @return
     */
    @PostMapping("/received")
    public BaseResult received(@RequestBody List<Long> ids){

        purchaseService.received(ids);

        return BaseResult.ok();
    }

    @PostMapping("/merge")
    public BaseResult merge(@RequestBody MergeVo mergeVo){

        purchaseService.mergePurchase(mergeVo);

        return BaseResult.ok();
    }


    @RequestMapping("/unreceive/list")
    //@RequiresPermissions("ware:purchase:list")
    public BaseResult unreceiveList(@RequestParam Map<String, Object> params){

        PageUtils page = purchaseService.unreceiveList(params);

        return BaseResult.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("ware:purchase:list")
    public BaseResult list(@RequestParam Map<String, Object> params){

        PageUtils page = purchaseService.queryPage(params);

        return BaseResult.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ware:purchase:info")
    public BaseResult info(@PathVariable("id") Long id){

		PurchaseEntity purchase = purchaseService.getById(id);

        return BaseResult.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ware:purchase:save")
    public BaseResult save(@RequestBody PurchaseEntity purchase){

		purchaseService.save(purchase);

        return BaseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ware:purchase:update")
    public BaseResult update(@RequestBody PurchaseEntity purchase){

		purchaseService.updateById(purchase);

        return BaseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ware:purchase:delete")
    public BaseResult delete(@RequestBody Long[] ids){

		purchaseService.removeByIds(Arrays.asList(ids));

        return BaseResult.ok();
    }

}
